//
//  XBAuctionController.m
//  寻宝之旅
//
//  Created by LyuBook on 16/3/27.
//  Copyright © 2016年 lvdingze. All rights reserved.
//

#import "XBAuctionController.h"

#import "XBAuction.h"

#import "XBAuctionGroup.h"

#import "XBCollectionViewCell.h"

#import "XBFlowLayout.h"

#import "HMReusableView.h"

@interface XBAuctionController ()

@property (nonatomic, strong) NSArray *auctions;
@property (nonatomic, strong) NSArray *auctionGroups;
@property (weak, nonatomic) IBOutlet XBFlowLayout *layout;
@end

@implementation XBAuctionController



- (void)viewDidLoad {
    [super viewDidLoad];
    
        self.collectionView.backgroundColor = [UIColor whiteColor];
        [XBAuctionGroup loadAuctionGroupseSuccess:^(NSArray *auctionGroups) {

            self.auctionGroups = auctionGroups;
            [self.collectionView reloadData];

            self.layout.count =  self.auctionGroups.count;
           
        }];
   //collection背景颜色
    self.collectionView.backgroundColor = [UIColor colorWithRed:242 / 255.0 green:242 / 255.0 blue:242 / 255.0 alpha:1];
    
   
}


#pragma mark -collectionview datasouce
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return self.auctionGroups.count;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    XBAuctionGroup *group = self.auctionGroups[section];
    
    NSInteger row = 0;
    if (section == 0) {
        row = 1;
    }else if (section == 1){
        row = group.auctions.count;
        
    }else if (section == 2){
        
        row = group.auctions.count;
    }else if (section == 3){
        
        row = group.auctions.count;
    }

    return row;
    
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    XBAuctionGroup *group = self.auctionGroups[indexPath.section];
    NSString *ID = @"";
    if (indexPath.section == 0) {
        ID = @"1";
    }else if (indexPath.section == 1){
        ID = @"2";
        XBCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
        cell.auction = group.auctions[indexPath.row];
        return cell;
    }else if(indexPath.section == 2){
        ID = @"3";
        XBCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
        cell.auction = group.auctions[indexPath.row];
        return cell;
    }else if(indexPath.section == 3){
        
        ID = @"4";
        XBCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
        cell.auction = group.auctions[indexPath.row];
        return cell;
    }
    
    XBCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    cell.auctionGroup = group;
    return cell;
}
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    NSString *ID=@"header";
    if (kind==UICollectionElementKindSectionFooter) {
        ID=@"footer";
    }
    HMReusableView *userView=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:ID forIndexPath:indexPath];
//    NSLog(@"%@",indexPath);
    userView.auctionGroup = self.auctionGroups[indexPath.section];
    return  userView;
}

@end
